package org.bet.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class DateUtils extends org.apache.commons.lang.time.DateUtils{
	public static Date parseDateIfPossible(DateFormat formatter, String dateText){
		try{
			
			return formatter.parse(dateText);
		}
		catch(Exception e){
			return null;
		}
	}

	public static String getCurrentDateAsString(String pattern) {
		DateFormat formatter = new SimpleDateFormat(pattern);
		try{
			return formatter.format(new Date());
		}
		catch(Exception e){
			return null;
		}
	}

	public static boolean isDateString(String dateText, String pattern) {
		try{
			DateFormat formatter = new SimpleDateFormat(pattern);
			formatter.parse(dateText);
			
			return true;
		}
		catch(Exception e){
			return false;
		}
	}

	public static String formatIfPossible(Date date, String pattern) {
		DateFormat formatter = new SimpleDateFormat(pattern);
		try{
			return formatter.format(date);
		}
		catch(Exception e){
			return null;
		}
	}
}
